<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    MvcCms -
    <%=ViewData["PageTitle"]%>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <style type="text/css">
        label.error
        {
            float: none;
            color: red;
            padding-left: .5em;
            vertical-align: top;
        }
    </style>
    <script type="text/javascript" src="/scripts/MvcCmsImageManager.js"></script>
    <script type="text/javascript" src="/scripts/ckeditor/ckeditor.js"></script>
    <script src="/scripts/ckeditor.js" type="text/javascript"></script>
    <link href="/content/ckeditor.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var editor;
        function changeEnter() {
            // If we already have an editor, let's destroy it first.
            if (editor)
                editor.destroy(true);

            // Create the editor again, with the appropriate settings.
            editor = CKEDITOR.replace('HTML',
		    {
		        enterMode: Number(1),
		        shiftEnterMode: Number(2),
		        height: "230"
		    });
            MvcCmsImages.SetupCKEditor(editor);
        }
        window.onload = changeEnter;
        //]]>
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="contentpage-outerdiv">
    <h2>
        <%=ViewData["PageTitle"]%></h2>
    <span class="field-validation-error">&nbsp;<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
    <%=ViewData["message"].ToString()%></span>
    <% using (Html.BeginForm("CreateWidget", "BackOffice", FormMethod.Post, new { id = "form1" }))
       {%>
    <fieldset>
        <legend>Widget Fields</legend>
        <p>
            <label for="TargetDiv">Is For Weighted Content</label>
            <%= Html.CheckBox("IsForWeightedContent", false, new { onclick = "ToggleNonWeightedSettings();", autocomplete="off" })%>
        </p>                
        <p>
            <label for="Title">
                Title:</label>
            <%= Html.TextBox("Title", "", new { @class = "required" })%>
        </p>
        <div id="non-weighted-settings">
            <table>
                <tr>
                    <td>
                        <label for="AllPages">
                            All Pages:</label>
                        <%= Html.RadioButton("AllPagesValue", "All", true, new { @class = "required" })%>
                    </td>
                    <td>
                        <label for="Category">
                            Category:</label>
                        <%= Html.RadioButton("AllPagesValue", "Cat", false)%><%= Html.DropDownList("CategoryID")%>
                    </td>
                    <td>
                        <label for="Page">
                            Page:</label>
                        <%= Html.RadioButton("AllPagesValue", "Page", false)%><%= Html.DropDownList("ContentPageID")%>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        Choose either all pages or a single page or a single category for the widget to
                        display on
                    </td>
                </tr>
            </table>
            <p>
                <label for="TargetDiv">
                    Target Div:</label>
                <%= Html.TextBox("TargetDiv", "")%>
            </p>
            <p>
                <label for="ZoneName">
                    Zone Name:</label>
                <%= Html.TextBox("ZoneName", "")%>
            </p>
        </div>
        <p>
            <label for="Summary">
                Description:</label>
            <%= Html.TextArea("Description")%>
            <%= Html.ValidationMessage("Description", "")%>
        </p>
        <p>
            <label for="HTML">
                HTML:</label>
            <%= Html.TextArea("HTML", "", new { @class = "mceEditor" })%>
            <%= Html.ValidationMessage("HTML", "")%>
        </p>
        <p>
            <label for="Body">
                Active:</label>
            <%= Html.CheckBox("Active")%>
            <%= Html.ValidationMessage("Active", "")%>
        </p>
        <p>
            <input type="button" onclick="SubmitForm();" value="Create" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%=Html.ActionLink("Back to List", "ManageWidgets")%>
    </div>
</div>     
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script type="text/javascript">
       var isForWeightedContent = false;
       function SubmitForm() {           
            if (isForWeightedContent) {
                $("#TargetDiv").val("weighted");                
            }
            else {
                var targetDivVal = $("#TargetDiv").val();
                if (!targetDivVal) {
                    alert("targetdiv is required");
                    return false;
                }                
            }
            $("#form1").submit();
        }

        function ToggleNonWeightedSettings() {
            if (isForWeightedContent) { isForWeightedContent = false; } else { isForWeightedContent = true; }
            $("#non-weighted-settings").toggle();
        }   
    </script>
</asp:Content>
